﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using SIOsystem.Model.ReportDataSetTableAdapters;
using SIOsystem.Model.OrderDataSetTableAdapters;

namespace SIOsystem.Control
{
    class ReportClass
    {
        static public DataTable getInOrderList(DateTime startDate, DateTime endDate, string keyword)
        {
            try
            {
                using (QuaryInOrderTableAdapter db = new QuaryInOrderTableAdapter())
                {
                    return db.QuaryInOrders(startDate, endDate, "%" + keyword + "%");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        static public DataTable getOutOrderList(DateTime startDate, DateTime endDate, string keyword,string OutName,long DeptID)
        {
            try
            {
                using (QuaryOutOrderTableAdapter db = new QuaryOutOrderTableAdapter())
                {
                    if (DeptID==-1)
                    {
                        return db.QuaryOutOrdersNoDept(startDate, endDate, "%" + keyword + "%", "%" + OutName + "%");
                    } 
                    else
                    {
                        return db.QuaryOutOrders(startDate, endDate, "%" + keyword + "%", "%" + OutName + "%", DeptID);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        static public DataTable getInOutDetail(DateTime startDate, DateTime endDate, long mainCID)
        {
            try
            {
                using (InOutDetailTableAdapter db = new InOutDetailTableAdapter())
                {
                    return db.GetInOutDetail(startDate, startDate, startDate, endDate, startDate, endDate
                                           , startDate, startDate, startDate, endDate, startDate, endDate
                                           , mainCID, mainCID);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        static public DataTable getDeptDetail(DateTime startDate, DateTime endDate, long DID)
        {
            try
            {
                using (DeptDetailTableAdapter db = new DeptDetailTableAdapter())
                {
                    if (DID == -1)
                    {
                        return db.GetDeptDetailNoDept(startDate, endDate );
                    }
                    return db.GetDeptDetail(startDate, endDate, DID);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

    }
}
